/**
 * @file bull_hal_sys_system.h
 * @brief 
 * @author yejing (yejh@gongniu.cn)
 * @version 1.0
 * @date 2024-05-09
 * 
 * Copyright 2021-2023 GongNiu Inc. All Rights Reserved.
 * 
 */


#ifndef _BULL_HAL_SYS_SYSTEM_H
#define _BULL_HAL_SYS_SYSTEM_H

#include "bull_hal_adapter.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @brief bull_hal_sys_sleep用于系统sleep
 * 
 * @param[in] msTime sleep time is ms
 */
void bull_hal_sys_sleep( uint32_t msTime );


/**
 * @brief 得到系统剩余内存
 * 
 * @return uint32_t 
 */
uint32_t bull_hal_sys_get_free_heap_size(void);

uint32_t bull_hal_sys_get_free_internal_8bit_heap_size( void );

uint32_t bull_hal_sys_get_free_largest_heap_size( void );

uint32_t bull_hal_sys_get_free_total_heap_size( void );
/**
 * @brief bull_hal_sys_get_tickcount 
 * @return SYS_TICK_T 
 */
uint32_t bull_hal_sys_get_tickcount(void);


/**
 * @brief bull_hal_sys_tickratems用于获取系统ticket是多少个ms
 * 
 * @return the time is ms of a system ticket
 */
uint32_t bull_hal_sys_get_tickratems(void);


/**
 * @brief gbull_hal_sys_is_in_isr用于检查系统是否处于中断上下文
 * 
 * @return true 
 * @return false 
 */
bool bull_hal_sys_is_in_isr(void);



/**
 * @brief bull_hal_sys_reset用于重启系统
 * 
 */
void bull_hal_sys_restart(void);

uint32_t bull_hal_sys_get_free_internal_minimum_heap_size( void );

/**
 * @brief bull_hal_sys_get_min_heap_size/最小剩余内存大小
 * 
 * @return int <0: don't support  >=0: mini heap size/free memory
 */
int bull_hal_sys_get_min_free_heap_size(void);

/**
 * @brief 获取得到内部剩余内存
 * 
 * @return uint32_t 
 */
uint32_t bull_hal_sys_get_free_internal_heap_size( void );


/**
 * @brief bull_hal_sys_get_rst_info 用于获取硬件重启原因
 * 
 * @return 硬件重启原因
 */
BULL_RST_REASON_E bull_hal_sys_get_reset_reason(void);


/**
 * @brief gn_os_adapt_get_random_data用于获取指定条件下的随机数
 * 
 * @param[in] range 
 * @return 随机数
 */
uint32_t  bull_hal_sys_get_random_data( IN uint32_t range);


/**
 * @brief 获取系统时间(输出结构体)
 * 
 * @return int 
 */
int bull_hal_sys_get_time( OUT BULL_TM_S *tm );

/**
 * @brief 获取系统时间 (输出字符串)
 * 
 * @return int 
 */
int bull_hal_sys_get_time_char( OUT char * nowtime );


/**
 * @brief 获取当前时间戳
 * 
 * @return TIME_T 
 */
time_t  bull_hal_get_now_timestamp( void );

/**
 * @brief 基于输入时间获取时间戳
 * 
 * @param timeinfo 
 * @return TIME_T 
 */
time_t  bull_hal_get_timestamp_base_time( BULL_TM_S timeinfo );


/**
 * @brief 设置系统时间
 * 
 * @param daya 
 * @param hour 
 * @param min 
 * @param sec 
 */
void bull_hal_set_sys_time( int daya, int hour, int min, int sec );

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif

